'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-04-09 19:26:07
'''
import sys
import numpy as np
from sklearn.metrics import roc_auc_score

dfm_inpath = '/data1/xuejian/sync/offline_train/rank_union/galaxy/result'
xgb_inpath = '/data1/xuejian/sync/offline_train/rank_union/xgboost/algorithm/xgb_preds_out_t'

dfm_pred = []
xgb_pred = []
all_label = []
with open(dfm_inpath, 'r') as f1, open(xgb_inpath, 'r') as f2:
    # for line in f1:
    for line in f2:
        # dfm_score = line.strip()
        dfm_score = f1.readline().strip()
        # f2_line = f2.readline().strip()
        f2_line = line.strip()
        # print(f2_line)
        xgb_score = f2_line.split('\t')[3]
        label = f2_line.split('\t')[4]
        dfm_pred.append(float(dfm_score))
        xgb_pred.append(float(xgb_score))
        all_label.append(int(label))
    # for line in f1:
    #     dfm_score = line.strip()
    #     f2_line = f2.readline().strip()
    #     xgb_score = f2_line.split('\t')[3]
    #     label = f2_line.split('\t')[4]
    #     dfm_pred.append(float(dfm_score))
    #     xgb_pred.append(float(xgb_score))
    #     all_label.append(int(label))

def cal_auc(label, pred):
    return roc_auc_score(np.asarray(label), np.asarray(pred))

print("dfm size: ", len(dfm_pred))
print("xgb size: ", len(xgb_pred))
print("label size: ", len(all_label))

dfm_auc = cal_auc(np.asarray(all_label), np.asarray(dfm_pred))
print("deepfm auc: ", dfm_auc)
xgb_auc = cal_auc(np.asarray(all_label), np.asarray(xgb_pred))
print("xgboost auc: ", xgb_auc)